
const axios = require('axios');
const cheerio = require('cheerio');
const fetchDetail = async (id, token) => {
    let config = {
        method: 'get',
        maxBodyLength: Infinity,
        url: `https://www.xiaohongshu.com/explore/${id}?xsec_token=${token}&xsec_source=pc_feed`,
        headers: {
            'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
            'accept-language': 'zh-CN,zh;q=0.9',
            'cache-control': 'no-cache',
            'cookie': 'abRequestId=aec348ac-4390-573f-9d93-617af756f36a; xsecappid=xhs-pc-web; a1=1943c266ddf1b46edpaex7hy4cvmdc51kmir3pai550000347772; webId=ff097b6629199cc3d5e40bdada7276c2; gid=yj4qSJKW4STYyj4qSJKKf6U0fiyD4KdfU0dC332Wxv4ShF286fS2yq888q4WWWJ8JJddj8J8; web_session=040069b17c2ea0561c80474fb1354b9e1daf1e; webBuild=4.55.1; websectiga=a9bdcaed0af874f3a1431e94fbea410e8f738542fbb02df1e8e30c29ef3d91ac; sec_poison_id=016a7794-b8a4-4002-bb2d-4c906420afe8; unread={%22ub%22:%226772a2a2000000000900ee85%22%2C%22ue%22:%22678c4cc8000000001d013f07%22%2C%22uc%22:14}; acw_tc=0a00d7ab17373998904027832e3c2f3a74856950a027ee97000f78429cce51',
            'pragma': 'no-cache',
            'priority': 'u=0, i',
            'sec-ch-ua': '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
            'sec-ch-ua-mobile': '?0',
            'sec-ch-ua-platform': '"Windows"',
            'sec-fetch-dest': 'document',
            'sec-fetch-mode': 'navigate',
            'sec-fetch-site': 'none',
            'sec-fetch-user': '?1',
            'upgrade-insecure-requests': '1',
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
        }
    };

    return axios.request(config)
        .then((response) => {
            const html = response.data
            const $ = cheerio.load(html)
            const text = $("#detail-desc").text()
            console.log(text)
            return text
        })
        .catch((error) => {
            console.log(error);
        });
}

module.exports = {
    fetchDetail
};